import React from 'react';
import { connect } from 'dva';
import { routerRedux } from 'dva/router';
import { createForm } from 'rc-form';
import content from '../../common/contentCss/content.css';
import styles from './common.css';
import CustTitle from '../../common/title/title';
import ProblemResponseList from './pages/problemResponseList/problemResponseList';

function Index({loading,dispatch,problemResponse}) {

  const { problemResponseInfo } = problemResponse;

  const titleProps = {
    titleName:'咨询回复',
    goBack(){
      dispatch(routerRedux.goBack());
    },
  }

  const problemResponseListProps = {
    list:problemResponseInfo,
    onCloseMessage(id){
      dispatch({
        type:'problemResponse/putCloseMessage',
        payload:{
          id
        }
      })
    },
    onViewPage(itemData){
      if(itemData.readed == 0){
        dispatch({
          type:'problemResponse/putCloseMessage',
          payload:{
            id:itemData.id
          }
        })
      }
      dispatch(routerRedux.push({
        pathname: '/part-time-detail',
        query: {
          id:itemData.jobId,
        }
      }));
    }
  }

  return (
    <div className={content.content}>
      <CustTitle {...titleProps}/>
      <div style={{marginTop: '2.9em'}}>
        <ProblemResponseList {...problemResponseListProps}/>
      </div>
    </div>
  )
}

function mapStateToProps(state, ownProps) {
  return {
    loading: state.loading.global,
    problemResponse: state.problemResponse,
  }
}
const IndexText = createForm()(Index);

export default connect(mapStateToProps)(IndexText);
